#include "listnode.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void testFunc1()
{
  Node * list = 0; /* always initialize */
  int v = 0;
  int i;
  for (i = 0; i < 10; i ++)
    {
      v = rand() % 1000;
      printf("insert %d\n", v);
      list = List_insert(list, v);
    } 
  List_print(list);
  List_destruct(list);
}
void testFunc2()
{
  Node * list1 = 0;
  Node * list2 = 0;
  Node * list3 = 0;
  int cnt;
  int v;
  for (cnt = 0; cnt < 10; cnt ++)
    {
      v = rand() % 1000;
      printf("insert %d\n", v);
      list1 = List_insert(list1, v);
      list2 = List_insert(list2, v);
    }
  List_print(list1);
  List_print(list2);
  list3 = List_copy(list1);
  List_assign(& list2, list2); /* destination = source */
  List_assign(& list1, list2);
  list1 = List_insert(list1, -91);
  list3 = List_insert(list3, 1003);
  List_print(list1);
  List_print(list2);
  List_print(list3);
  List_destruct(list1);
  List_destruct(list2);
  List_destruct(list3);
}

void testFunc3()
{
  Node * list1 = 0;
  Node * list2 = 0;
  int cnt;
  for (cnt = 0; cnt < 10; cnt ++)
    {
      list1 = List_insert(list1, cnt + 10);
    }
  List_print(list1);
  printf("search %d = %d\n", 6, List_search(list1, 6, & list2));
  List_print(list2);
  printf("search %d = %d\n", 16, List_search(list1, 16, & list2));
  List_print(list2);
  printf("search %d = %d\n", 19, List_search(list1, 19, & list2));
  List_print(list2);
  printf("search %d = %d\n", 10, List_search(list1, 10, & list2));
  List_print(list2);

  printf("delete %d = %d\n", 3, List_delete(& list1, 3));
  List_print(list1);
  printf("delete %d = %d\n", 13, List_delete(& list1, 13));
  List_print(list1);

  printf("delete %d = %d\n", 10, List_delete(& list1, 10));
  List_print(list1);

  printf("delete %d = %d\n", 19, List_delete(& list1, 19));
  List_print(list1);

  List_destruct(list1);
  /* do not List_destruct(list2) because it points to one node
     in list1 */
}

int main(int argc, char * argv[])
{
  srand(time(0));
  testFunc1();
  testFunc2();
  testFunc3();
  return 0;
}

